﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Input;

namespace NetLogger
{
	public class NetReport : NetActivity, ICommand
	{
		public string Report
		{
			get
			{
				return Details;
			}
			set
			{
				Details = value;
				OnCanExecuteChanged();
			}
		}

		private DateTimeOffset _enterTime;
		private TimeSpan _enterDelay = TimeSpan.Zero;

		public string ReportDelay
		{
			get
			{
				return Convert.ToInt32( _enterDelay.TotalMinutes ).ToString();
			}
			set
			{
				double
					delay;

				if ( double.TryParse( value, out delay ) )
				{
					_enterDelay = TimeSpan.FromMinutes( delay );
					Time = ( _enterTime - _enterDelay );
				}
			}
		}

		public NetReport( NetMember member )
			: base( DateTimeOffset.UtcNow, NetActivityTypes.NewReport, null, member )
		{
			_enterTime = Time;
		}

		public bool CanExecute( object parameter )
		{
			return !string.IsNullOrWhiteSpace( Details );
		}

		public event EventHandler CanExecuteChanged;

		private void OnCanExecuteChanged()
		{
			EventHandler
				h = CanExecuteChanged;

			if ( h != null )
				h( this, new EventArgs() );
		}

		public void Execute( object parameter )
		{
			Location = Member.Location;
			Member.AddReport( this );
		}
	}
}
